package com.jjy.dao.impl;

import com.jjy.dao.UserDao;
import com.jjy.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDaoImpl implements UserDao{
  private SqlSessionFactory sqlSessionFactory;
  public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
    this.sqlSessionFactory = sqlSessionFactory;
  }
  @Override
  public User selectUserById(int id) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    User  user = sqlSession.selectOne("selectUserById" , 1);
    return user;
  }

  @Override
  public List<User> selectUserList() {
    return null;
  }

  @Override
  public List<User> selectUserByParams(User user) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.selectList("selectUserByParams" , user);
  }

  @Override
  public int createUser(User user) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.insert("createUser" , user);
  }

}
